import http from '@/utils/request'

const apiBefore = 'web/bots'

export const bots = {
  getTenantBotListApi: params => {
    return http.get(`${apiBefore}/tenant/bot/` + params.tenantCode + '/all', { params })
  },
  getBotListApi: params => {
    return http.get(`${apiBefore}/sys/bot/list-integration`, { params })
  },
  getBotListApiForApp: params => {
    return http.get(`${apiBefore}/sys/bot/simple-list`, { params })
  },
  getTenantBotInfoApi: (params) => {
    return http.get(`${apiBefore}/tenant/bot/` + params.id + '/info', { params })
  },
  getTenantScriptListApi: (params) => {
    return http.get(`${apiBefore}/sys/script/list`, { params })
  },
  getScriptListApi: (params) => {
    return http.get(`${apiBefore}/sys/script/list-detail`, { params })
  },
  updateTenantScriptApi: params => {
    return http.post(`${apiBefore}/tenant/script`, params)
  },

  updateTenantScriptSwitchApi: params => {
    if (params.isBot) {
      return http.put(`${apiBefore}/sys/bot/${params.id}/enable`, { enable: params.enable }, {}, { cache: { enable: true } })
    }
    return http.post(`${apiBefore}/tenant/script/switch`, params, {}, { cache: { enable: false } })
  },
  getTenantScriptInfoApi: id => {
    return http.get(`${apiBefore}/tenant/script/` + id + '/info')
  },
  getBotsListApi: params => {
    return http.get(`${apiBefore}/sys/script/select-list`, { params })
  },

  getBotsStoreListApi: params => {
    return http.get(`${apiBefore}/sys/bot/list-store`, { params })
  },
  publishBotApi: params => {
    return http.post(`${apiBefore}/sys/bot/publish`, params)
  },

  getDatasetLogsListApi: params => {
    return http.get(`${apiBefore}/sys/scheduleLog/page`, { params })
  },
  getBotDataSelectList: (url, params) => {
    return http.get(url, { params })
  },

  getBotByDatasetListApi: params => {
    return http.get(`${apiBefore}/sys/bot/list-params`, { params })
  },
  getBotRunHistoryList: params => {
    return http.get(`${apiBefore}/sys/bot/log/page-running`, { params })
  },
  getBotHistoryDetail: params => {
    return http.get(`${apiBefore}/sys/bot/log/detail`, { params })
  },
  getBotIdByOriginalId: originalId => {
    return http.get(`${apiBefore}/sys/bot/${originalId}/getBotId`)
  },
  clearBotsCacheApi: params => {
    return http.get(`${apiBefore}/sys/memoryCache/refreshAllTenantCache/${params.type}`)
  },
  getWidgetByBotsList: params => {
    return http.get(`${apiBefore}/sys/bot/list-by-datasource`, { params })
  },
  botNumber: () => {
    return http.get(`${apiBefore}/sys/bot/botNumber`)
  }, 
}

export const botStore = {
  getTenantBotListApi: params => {
    return http.get(`${apiBefore}/sys/bot/list`, { params })
  },
  getTenantBotInfoApi: (params) => {
    return http.get(`${apiBefore}/sys/bot/` + params.id + '/info', { params }, { cache: { enable: false } })
  },
  putBotUpdateScriptApi: (id, params) => {
    return http.put(`${apiBefore}/sys/bot/${id}/update-script`, params)
  },
  updateBotRuleApi: (params, id) => {
    return http.post(`${apiBefore}/sys/script`, params)
  },
  getChannelList: params => {
    return http.get(`${apiBefore}/teams/channels/select-list`, { params })
  },
  updateBotIntegrationApi: params => {
    return http.post(`${apiBefore}/sys/bot/update-integration`, params)
  },
  getKeyOptions: params => {
    return http.post(`${apiBefore}/sys/bot/list-field`, params)
  }

}
